#include <QtGui>
#include <QtSql>
#include <QString>

#include "./include/ctrlSettingDlg.h"

CtrlSettingDlg::CtrlSettingDlg(QWidget *parent)
    : QDialog(parent)
{
    setWindowFlags(Qt::FramelessWindowHint);
    setWindowTitle(QString::fromUtf8("设置"));
    setFixedSize(800, 480);

    CreateWidget();
    CreateLayout();
}

void CtrlSettingDlg::CreateWidget()
{
    model = new QSqlRelationalTableModel(this);
    model->setTable("itemInfo");
    model->setSort(1, Qt::AscendingOrder);
    model->setHeaderData(1, Qt::Horizontal, QString::fromUtf8("区号"));
    model->setHeaderData(2, Qt::Horizontal, QString::fromUtf8("楼栋号"));
    model->setHeaderData(3, Qt::Horizontal, QString::fromUtf8("层号"));
    model->setHeaderData(4, Qt::Horizontal, QString::fromUtf8("房号"));
    model->setHeaderData(5, Qt::Horizontal,QString::fromUtf8("设备名"));
    model->select();

    view = new QTableView;
    view->setModel(model);
    view->setItemDelegate(new QSqlRelationalDelegate(this));
    view->setSelectionMode(QAbstractItemView::SingleSelection);
    view->setSelectionBehavior(QAbstractItemView::SelectRows);
    view->setColumnHidden(0, true);
    view->resizeColumnsToContents();
    view->horizontalHeader()->setStretchLastSection(true);

    editBtn = new QPushButton(QString::fromUtf8("编辑"));
    closeBtn = new QPushButton(QString::fromUtf8("退出"));

    connect(editBtn, SIGNAL(clicked()), this, SLOT(edit()));
    connect(closeBtn, SIGNAL(clicked()), this, SLOT(close()));
}

void CtrlSettingDlg::CreateLayout()
{
    QVBoxLayout *rightLayout = new QVBoxLayout;
    rightLayout->addWidget(editBtn);
    rightLayout->addWidget(closeBtn);
    rightLayout->addSpacing(10);

    QHBoxLayout *mainLayout = new QHBoxLayout;
    mainLayout->addWidget(view);
    mainLayout->addLayout(rightLayout);
    setLayout(mainLayout);

}

void CtrlSettingDlg::edit()
{

}

